<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1',function ($api){
    $api->group(['namespace' => 'App\Http\Controllers\Api','middleware'=>['merge']], function ($api) {
        $api->get('/','IndexController@index');
        //返回所有启用的栏目
        $api->get('category','CategoryController@category');
        //返回秒杀和非秒杀商品
        $api->get('products/list','ProductController@list');
        //商品详情
        //$api->get('product/{id}','ProductController@product')->where('id','[0-9]+');
        $api->get('product','ProductController@product');
        $api->get('productCommentList','ProductController@comment_list');
        //微信登录
        $api->post('login','LoginController@login')->name('login');
        //支付结果通知
        $api->any('notify','OrderController@notify')->name('notify');
        $api->any('refund/notify','OrderController@notify')->name('notify');

        $api->get('settlement','ProductController@settlement')->name('settlement');


    });
    //需要验证微信登陆的路由
    $api->group(['namespace' => 'App\Http\Controllers\Api','middleware'=>['wechat.login','merge']],function ($api){
        //++++++++++++++++++++++++++
        //  订单模块
        //++++++++++++++++++++++++++
        //支付初始化
        $api->post("create_order_init","OrderController@create_order_init")->name('create_order_init');
        //支付
        $api->post("do_cash","OrderController@do_cash")->name('do_cash');
        //订单详情
        $api->get('order_detail','OrderController@detail');
        //我的订单
        $api->get('my_order','OrderController@my_order');
        //各种类型的订单数量查询
        $api->get('order_num_by_group','OrderController@order_num_by_group');
        //确认收货
        $api->post('receive','OrderController@receive');
        //订单评价
        $api->post('comment', 'OrderController@comment');

        //+++++++++++++++++
        //收获地址模块
        //+++++++++++++++++
        //添加地址
        $api->post("add_address", 'AddressController@add_address')->name("add_address");
        //查询收获地址列表
        $api->get("address_list", 'AddressController@address_list')->name("address_list");
        //查询单个地址
        $api->get("address_info", 'AddressController@address_info')->name("address_info");
        //更新某个地址
        $api->post("update_address", 'AddressController@update_address')->name("update_address");
        //删除某个地址
        $api->post("delete_address", 'AddressController@delete_address')->name("delete_address");


        //完成用户的取货门店选择
        $api->post('select_delivery_done','UserController@select_delivery_done');


        //我的一级好友
        $api->get('first_friends','UserController@first_friends')->name('first_friends');
        //我的二级好友
        $api->get('second_friends','UserController@second_friends')->name('second_friends');
        //核销订单
        $api->post('use_order','OrderController@use_order')->name('use_order');
        //我的小程序码
        $api->get('my_mpcode','UserController@my_mpcode')->name('my_mpcode');
        //用户详情
        $api->get('user_info','UserController@user_info')->name('user_info');
        //用户金币记录
        $api->get('money','UserController@money')->name('user.money');

        //用户提现
        $api->post('withdraw','UserController@withdraw')->name('user.withdraw');


        //+++++++++++++++++++++
        //  购物车模块
        //+++++++++++++++++++++
        //添加购物车
        $api->post('add_cart','CartController@add_cart')->name('add_cart');
        $api->post('delete_cart','CartController@delete_cart')->name('delete_cart');
        //购物车列表
        $api->get('shopping_cart','CartController@shopping_cart')->name('shopping_cart');
        //购物车数量
        $api->get('cart','CartController@cart')->name('cart');



    });

    //公共部分
    $api->group(['namespace'=>'App\Http\Controllers\Common','middleware'=>['merge']],function ($api){
        //返回城市列表
        $api->get('cities','ProvinceController@city');
        //返回某个城市的区
        $api->get('district','ProvinceController@district');

        //返回某城市的取货门店
        $api->get('deliveries','DeliveryController@deliveries');
        //返回开通了取货门店的城市
        $api->get('delivery_cities','ProvinceController@delivery_cities');
    });
});
